package com.jjwxc.jwjskandriod.activity;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import androidx.constraintlayout.widget.ConstraintLayout;

import com.jjwxc.jwjskandriod.R;
import com.jjwxc.jwjskandriod.config.BaseActivity;
import com.jjwxc.jwjskandriod.config.Url;
import com.jjwxc.jwjskandriod.framework.http.FFNetWork;
import com.jjwxc.jwjskandriod.framework.http.FFNetWorkCallBack;
import com.jjwxc.jwjskandriod.model.ReportResponse;
import com.jjwxc.jwjskandriod.model.UserProfileRequest;

public class InformationActivity extends BaseActivity {

    private TextView tv_nickName;
    private TextView tv_userNum;
    private TextView tv_phone;
    private ConstraintLayout cl_daochu;
    @Override
    public int getContentViewId() {
        return R.layout.activity_information;
    }

    @Override
    public void findView() {
        tv_nickName=findViewById(R.id.tv_nickName);
        tv_userNum=findViewById(R.id.tv_userNum);
        tv_phone=findViewById(R.id.tv_phone);
        cl_daochu=findViewById(R.id.cl_daochu);

    }

    @Override
    public void setListener() {
        cl_daochu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new FFNetWork().post(Url.getExportUserUrl, null, new FFNetWorkCallBack<ReportResponse>() {
                    @Override
                    public void onSuccess(ReportResponse response) {
                        if (response.getCode() == 200) {
                            Intent intent = new Intent(InformationActivity.this, WebActivity.class);
                            intent.putExtra("WEB_URL", response.getData());
                            intent.putExtra("WEB_NAME", "导出您的个人信息");
                            startActivity(intent);
                        }

                    }

                    @Override
                    public boolean onFail(ReportResponse response) {
                        return false;
                    }
                }, ReportResponse.class);

            }
        });
    }

    @Override
    public void afterCreate() {
        post(Url.getUserProfile, null, UserProfileRequest.class, new FFNetWorkCallBack<UserProfileRequest>() {
            @Override
            public void onSuccess(UserProfileRequest response) {
                if (response.getCode() == 200) {
                    tv_nickName.setText(response.getData().getNickname());

                    //进行加密
                    String phone = response.getData().getMobile().substring(0,3)+"****"+response.getData().getMobile().substring(7,response.getData().getMobile().length());

                    tv_phone.setText(phone);
                    tv_userNum.setText(response.getData().getUserNumber());
                }


            }

            @Override
            public boolean onFail(UserProfileRequest response) {
                return false;
            }
        });
    }
}
